import * as THREE from 'three'

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
export default class Base {
    constructor(ref) {
        // 创建场景
        this.ref = ref
        this.scene = new THREE.Scene()
        // 透视相机创建
        var width = ref.offsetWidth; //canvas画布宽度
        var height = ref.offsetHeight; //canvas画布高度
        console.log(ref.offsetWidth)
        this.width = width
        this.height = height
        this.camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000)
        // this.camera.position.set(10, 10, 10); //设置相机位置
        this.camera.lookAt(this.scene.position); //设置相机方向(
        // 创建渲染器
        this.renderer = new THREE.WebGLRenderer({ antialias: true })
        this.renderer.setSize(this.width, this.height)

        // 使物体更加清晰
        console.log(window.devicePixelRatio);
        this.renderer.setPixelRatio(window.devicePixelRatio)
        ref.appendChild(this.renderer.domElement)


    }
    update() {
        this.renderer.render(this.scene, this.camera)
    }
    // 自适应 
    /**
     * ! var-translate-en
     * ? 
     * *ss
     * todo addUsers
     * 用户列表
     */
    resize() {
        this.camera.aspect = this.ref.offsetWidth / this.ref.offsetHeight
        this.camera.updateProjectionMatrix()
     
        this.renderer.setSize(this.ref.offsetWidth , this.ref.offsetHeight)
    }
    // 环境光
    addAmbientLight(intensity = 1, color = 0xffffff) {
        const light = new THREE.AmbientLight(color, intensity);
        this.scene.add(light)

    }
}